package com.winderinfo.yikaotianxia.ui.videolearning;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.ui.zixun.InformationListBean;

import java.util.List;

public class LearningAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<LearningBean.RowsBean> list;

    public LearningAdapter(Context context, List<LearningBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_videoone, viewGroup, false);
        SelectedViewHolder selectedViewHolder = new SelectedViewHolder(view);
        return selectedViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
        SelectedViewHolder selectedViewHolder = (SelectedViewHolder) viewHolder;
        selectedViewHolder.vide_title.setText(list.get(i).getChapterName());
        selectedViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onUrl != null) {
                    onUrl.getId("http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4");
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectedViewHolder extends RecyclerView.ViewHolder {

        private final TextView vide_title, vide_xue;
        private final ImageView vide_download;

        public SelectedViewHolder(@NonNull View itemView) {
            super(itemView);
            vide_title = itemView.findViewById(R.id.vide_title);
            vide_xue = itemView.findViewById(R.id.vide_xue);
            vide_download = itemView.findViewById(R.id.vide_download);
        }
    }

    //接口回调
    public interface OnUrl {
        void getId(String url);
    }

    public OnUrl onUrl;

    public void setOnUrl(OnUrl onUrl) {
        this.onUrl = onUrl;
    }

}
